This page last changed on Oct 11, 2010 by smaddox.

This page tells you how to create a user macro that embeds an expandable text box into your page. (For full details about creating a user macro, see the guide to writing user macros.)

A Working User Macro

This is a working user macro that you may want to install onto your Confluence site. In a future release, we intend to bundle this user macro with Confluence. At present, we are making it available on this documentation page so that you can try it out.

Defining the 'Expand' User Macro

To create the 'Expand' user macro,

  1. Go to the Confluence Administration Console and click 'User Macros' in the left-hand panel.
  2. Click the link on the text 'Click here to create a new User Macro' at the top of the list of macros.
  3. Enter the macro attributes as follows:
    • Macro Name: expand
    • Visibility: Visible to all users in the Macro Browser
    • Macro Title: Expand
    • Description: Embeds an expandable text box into your page
    • Categories – Formatting
    • Icon URL: /images/icons/macrobrowser/expand.png
    • Documentation URL: http://confluence.atlassian.com/x/UBpODQ
    • Macro Body Processing: Convert wiki markup to HTML
    • Output Format: HTML
    • Template:
      ## @param title:title=Expand Title|type=string|required=false|desc=Title for the text to expand|default=Click here to expand...
      ##
      ## Check for a blank first parameter
      ##
      #if ($paramtitle && $paramtitle.length() > 0)
         #set ($expandtitle = $paramtitle)
      #elseif ($param0 && $param0.length() > 0)
         #set ($expandtitle = $param0)
      #else
         #set ($expandtitle = "Click here to expand...")
      #end
      #set ($toggleId = $action.random)
      #set ($imagePath = "${bootstrap.webAppContextPath}/images/icons")
      #set ($imageRight = "$imagePath/arrow_right.png")
      #set ($imageDown = "$imagePath/arrow_down.png")
      ##
      ## Toggle body div and icon when expander clicked.
      ##
      <script>
         // preload open image (variable not used elsewhere)
         new Image().src = "$imageDown";
         function expandmacroExpand(clickee) {
             var expander = jQuery(clickee);
             if (!expander.hasClass("on")) {
                 // open
                 expander.find("img").attr("src", "$imageDown");
                 expander.next().show();
                 expander.addClass("on");
             } else {
                 // close
                 expander.removeClass("on");
                 expander.next().hide();
                 expander.find("img").attr("src", "$imageRight");
             }
         };
      </script>
      ##
      ## Show title
      ##
      <div id="expander-$toggleId" style="cursor: pointer; text-decoration:none;" onclick="expandmacroExpand(this)">
      <span style="display: inline-block; width: 20px;">
       <img src="$imageRight" style="vertical-align: middle; text-decoration:none;">
      </span><span style="vertical-align: middle; text-decoration:none;">$generalUtil.htmlEncode($expandtitle)</span>
      </div>
      ##
      ## Show content
      ##
      <div style="display: none; margin-left: 20px;">$!body</div>
      
  4. Click 'Save'.

Using the 'Expand' Macro on a Page

See the user guide for the Expand macro.

RELATED TOPICS

Writing User Macros

Document generated by Confluence on Oct 12, 2010 20:44